<template>
      <!--新增界面-->
      <el-dialog title="新增" :visible.sync ="addFormVisible" :close-on-click-modal="false">
        <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
          <el-form-item label="地址" prop="name">
            <el-input v-model="addForm.walletAddressHash" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item  label="状态">
            <el-select v-model="addForm.useStatus" style="width: 100px;">
              <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item  label="类型">
            <el-select v-model="addForm.accountType"  style="width: 100px;">
              <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click.native="addFormVisible = false">取消</el-button>
          <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
        </div>
      </el-dialog>
</template>

<script>
  import API from '../../api/api_book';
  import {base_url} from 'api/index';
  import moment from 'moment';
  export default {
    data() {
      return {
        statusOptions: [{
          value: 'true',
          label: '激活'
        },{
          value: 'false',
          label: '未激活'
        }],
        typeOptions: [{
          value: 'USDT',
          label: 'USDT'
        },{
          value: 'BITCOIN',
          label: 'BITCOIN'
        }]
      }
    },
    methods: {
      //新增
      addSubmit: function () {
        let that = this;
        this.$refs.addForm.validate((valid) => {
          if (valid) {
            that.loading = true;
            let para = Object.assign({}, this.addForm);
            //para.publishAt = (!para.publishAt || para.publishAt === '') ? '' : util.formatDate.format(new Date(para.publishAt), 'yyyy-MM-dd');
            API.addCold(para).then(function (result) {
              that.loading = false;
              console.log(result);
              if (result && parseInt(result.code) === 200) {
                that.$message.success({showClose: true, message: result.msg, duration: 2000});
                that.$refs['addForm'].resetFields();
                that.addFormVisible = false;
                that.search();
              } else {
                that.$message.error({showClose: true, message: result.msg, duration: 2000});
              }
            }, function (err) {
              that.loading = false;
              that.$message.error({showClose: true, message: err.toString(), duration: 2000});
            }).catch(function (error) {
              that.loading = false;
              console.log(error);
              that.$message.error({showClose: true, message: '请求出现异常', duration: 2000});
            });

          }
        });
      }
    }
  }
</script>

<style scoped>

</style>
